import axios from 'axios'
import { Dialog } from 'vant'

const http = axios.create({
  baseURL: '/api',
  timeout: 5000,
})

// 添加响应拦截器
http.interceptors.response.use((response) => {
  const { data: _data } = response
  const { data, code, msg } = _data
  if (code !== 0) {
    Dialog.alert({
      message: msg,
    }).then(() => {
      //关闭弹窗的逻辑
    })
    return Promise.reject(msg)
  }
  return data
})

export default http
